﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SteamSwitch
{
    public partial class Form_UserManage : Sunny.UI.UIEditForm
    {
        public Form_UserManage()
        {
            InitializeComponent();
        }

        private void Form_UserManage_Load(object sender, EventArgs e)
        {
            dgv_User.Rows.Clear();
            //检测配置文件中是否有Steam登陆账户
            Configuration conf = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            if (conf.AppSettings.Settings.Count > 0)
            {
                foreach (KeyValueConfigurationElement item in conf.AppSettings.Settings)
                {
                    dgv_User.Rows.Add(new object[]
                    {
                        item.Key
                    }) ;
                }
            }
        }

        private void Form_UserManage_ButtonOkClick(object sender, EventArgs e)
        {
            Configuration conf = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            conf.AppSettings.Settings.Clear();
            foreach (DataGridViewRow item in dgv_User.Rows)
            {
                if (item.Index != dgv_User.Rows.Count-1) 
                {
                    conf.AppSettings.Settings.Add(item.Cells["Col_User"].Value.ToString(), "");
                }
            }
            conf.Save(ConfigurationSaveMode.Full);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void Form_UserManage_ButtonCancelClick(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.No;
            this.Close();
        }
    }
}
